//
//  LoginController.m
//  village_ios
//
//  Created by mac on 2019/8/11.
//  Copyright © 2019 com.sw.village. All rights reserved.
//

#import "RegisterPasswordController.h"
#import "RegisterRequest.h"
#import "UIStoryboard+Helper.h"

@interface RegisterPasswordController ()
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *nextPasswordTextField;

@end

@implementation RegisterPasswordController

+ (instancetype)instanceWithStoryBoard {

    NSString *className = NSStringFromClass([self class]);
    id vc = [UIStoryboard storyboardWithName:@"RegisterController" viewControllerIdentifier:className];
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (IBAction)toDone:(id)sender {
    
    //校验
    if (self.passwordTextField.text == nil ||
        self.nextPasswordTextField.text == nil) {
        [SYProgressHUD showInfoText:@"密码不能为空"];
        return;
    }
    
    if ([self.passwordTextField.text isEqualToString:self.nextPasswordTextField.text]) {
        [SYProgressHUD showInfoText:@"密码不一致"];
        return;

    }
    //参数
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (self.passwordTextField.text) {
        self.registerRequest.password = self.passwordTextField.text;
    }
    NSDictionary *dict =  [self.registerRequest mj_keyValues];
    [params addEntriesFromDictionary:dict];
    
    [SYProgressHUD show];
    [APIManager requestWithUrlString:@"api/auth/register" params:params method:@"POST" success:^(id response) {
        
        [self reloadAllData];
    } failure:^(NSError *error) {
        [self reloadErrorData];
    }];
}

@end
